<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div id="root">
    <!--遍历数组-->
    <h2>人员列表</h2>
    <button @click="update">更新马冬梅的信息</button>
    <ul>
        <li v-for="p in people" :key="p.id">
            {{p.name}}--{{p.age}}岁--{{p.gender}}
        </li>
    </ul>
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false;
    const vm = new Vue({
        el: '#root',
        data() {
            return {
                people: [
                    {id: '001', name: '马冬梅', age: 18, gender: '女'},
                    {id: '002', name: '周冬雨', age: 19, gender: '女'},
                    {id: '004', name: '温兆伦', age: 21, gender: '男'},
                    {id: '003', name: '周杰伦', age: 20, gender: '男'},
                ],
            }
        },
        computed: {},
        methods: {
            update(e){
                // 以下代码可行
                /*this.people[0].name = "马老师";
                this.people[0].age = 50;
                this.people[0].gender = "男";*/

                // 以下代码不可行
                this.people[0] = {id: '001', name: '马老师', age: 50, gender: '男'};
            }
        },
        watch: {}
    });
</script>
</html>